class Solution
{
public:
    int countLatticePoints(vector<vector<int>> &circles)
    {
        //  横纵坐标均在[0, 200]内, 可以用一个整数的8个bit表示
        unordered_set<int> coveredPoints;
        for (auto &circle : circles)
        {
            int xc = circle[0];
            int yc = circle[1];
            int r = circle[2];
            for (int x = xc - r; x <= xc + r; ++x)
            {
                for (int y = yc - r; y <= yc + r; ++y)
                {
                    if (squareDistance(x, y, xc, yc) <= r * r)
                    {
                        coveredPoints.insert(toCoordinateNum(x, y));
                    }
                }
            }
        }
        return coveredPoints.size();
    }

    inline int getX(int coordinate)
    {
        return coordinate & 0xFF;
    }

    inline int getY(int coordinate)
    {
        return (coordinate & 0xFF00) >> 8;
    }

    inline int toCoordinateNum(int x, int y)
    {
        return x + (y << 8);
    }

    inline int squareDistance(int x1, int y1, int x2, int y2)
    {
        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    }
};